classdef JUMP

    properties
        m
        cycle
        frame
        
        % can a phase jump happen

    end

    methods

        function self = JUMP(exp)

            % Find out in which bit is the center of the occluder
            op = (exp.occluder.X + exp.occluder.W*0.5);
            op = acos(op/(exp.fix.x*exp.scn.w/2))/ (2*pi);
            n = 1 + round(rand(exp.num_trials,exp.num_blocks));
            
            W = 0.9*min(exp.occluder.W(:))/2; % 0.9 is a short buffer 
            S = abs(exp.scn.w * exp.fix.x)/2;
            P = (exp.occluder.X +  exp.occluder.W/2)/S;
            P_r = real(acos((exp.occluder.X +  exp.occluder.W/2)/S))/(2*pi);

            % It assumest that the center of the occluder is always, ALWAYS
            % inside the amplitude of the movement.

            self.m = P_r - real(acos(P + W * round(2*rand(size(S)) - 1)/S)/(2*pi));
            
            % If its entering
            for i = 1:exp.num_blocks * exp.num_trials
                   if rand >= 0.5
                       op(i) = 1 - op(i);
                       self.m(i)  = -self.m(i);
                   end
            end
            self.frame = op + n;
            % No jump
            self.m(exp.FpC ~= exp.FpCoccPE) = 0;
        end

    end
end